package com.servicesystem.servicesystem.untis;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {

    private Integer code = 200;
    private String message;
    private Map<String, Object> dataMap;
    private static R r = new R();

    public R() {
        dataMap = new HashMap<>();
    }

    public static R success() {
        r.dataMap.clear();
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    public static R success(String message) {
        r.dataMap.clear();
        r.setCode(200);
        r.setMessage(message);
        return r;
    }

    public static R success(String message, Object data) {
        r.dataMap.clear();
        r.setCode(200);
        r.setMessage(message);
        r.dataMap.put("data", data);
        return r;
    }

    public static R success(Object data) {
        r.dataMap.clear();
        r.setCode(200);
        r.setMessage("成功");
        r.dataMap.put("data", data);
        return r;
    }

    public static R success(Integer code, String message, Object data) {
        r.dataMap.put("data", data);
        r.setMessage(message);
        r.setCode(code);
        return r;
    }

    public static R fail(Integer code, String message, Object data) {
        r.dataMap.clear();
        r.dataMap.put("data", data);
        r.setMessage(message);
        r.setCode(code);
        return r;
    }

    public R data(Object data) {
        r.dataMap.put("data", data);
        return r;
    }

    public R data(String key, Object data) {
        r.dataMap.put(key, data);
        return r;
    }

    public static R fail(Integer code, String message) {
        r.dataMap.clear();
        r.setMessage(message);
        r.setCode(code);
        return r;
    }

    public static R fail(String message) {
        r.dataMap.clear();
        r.setMessage(message);
        r.setCode(500);
        return r;
    }
}
